package com.dhnsoft.代码随想录.字符串;

/**
 * ClassName: d05_右旋字符串
 * Package: com.dhnsoft.代码随想录.字符串
 * Description:
 *
 * @Author dhn
 * @Create 2024/3/19 9:57
 * @Version 1.0
 */
public class d05_右旋字符串 {

    public static void main(String[] args) {
        String abcdefg = rightStr("abcdefg", 2);
        System.out.println(abcdefg);
    }

    public static String rightStr(String str,int k){
        char[] chars = str.toCharArray();
        StringBuilder result = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();
        StringBuilder sb3 = new StringBuilder();
        int len = chars.length;
        for (int i=0;i<len;i++){
            if(i>len-k-1){
                sb3.append(chars[i]);
            }
            else{
                sb2.append(chars[i]);
            }

        }
        result.append(sb3.reverse()).append(sb2);
        return result.toString();
    }
}
